package com.yogee.topseller.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yogee.core.utils.ToastUtils;
import com.yogee.topseller.R;
import com.yogee.topseller.activity.PayActivity;
import com.yogee.topseller.activity.XzcfActivity;
import com.yogee.topseller.activity.ZhoubianActivity;
import com.yogee.topseller.activity.tianyan.BzxrDetailActivity;
import com.yogee.topseller.activity.tianyan.GphqDetailActivity;
import com.yogee.topseller.activity.tianyan.GqczDetailActivity;
import com.yogee.topseller.bean.FengxianBean;
import com.yogee.topseller.bean.JigouBean;
import com.yogee.topseller.utils.Constants;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @auathor ${XiaoJianghong}
 * @date 2017/6/26.
 */

public class FengxianItemAdapter extends RecyclerView.Adapter<FengxianItemAdapter.ItemHolder> {

    private Activity context;
    private List<FengxianBean.Btn> beans = new ArrayList<>();


    private PayActivity.Listener listener;

    public FengxianItemAdapter(Activity context) {
        this.context = context;
    }

    public void addData(List<FengxianBean.Btn> beans) {
        this.beans = beans;
        notifyDataSetChanged();
    }

    public void setListener(PayActivity.Listener listener){
        this.listener = listener;
    }

    @Override
    public ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_fengxian_item, parent, false);
        return new ItemHolder(view);
    }

    @Override
    public void onBindViewHolder(ItemHolder holder, final int position) {
        holder.tab_item_img.setImageResource(beans.get(position).getRes());
        holder.tab_item_textview.setText(beans.get(position).getName());


        holder.ll_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // 行政处罚 || 个人风险 || 债券信息
                if(beans.get(position).getCode().equals(Constants.EyeCheck_XZRF_TYPE)
                        ||beans.get(position).getCode().equals(Constants.EyeCheck_RFX_TYPE)
                        ||beans.get(position).getCode().equals(Constants.EyeCheck_ZJXX_TYPE)){
                    context.startActivity(new Intent().setClass(context, XzcfActivity.class)
                            .putExtra("title",beans.get(position).getName())
                            .putExtra("type",beans.get(position).getCode())
                            .putExtra("proId",((ZhoubianActivity)context).getMySelectCompany().getProId())
                            .putExtra("cmpanyType",((ZhoubianActivity)context).getMySelectCompany().getType())
                            .putExtra("companyId",((ZhoubianActivity)context).getMySelectCompany().getId()));
                // 被执行人 || 股本结构 || 股票分红 || 股本变动  失信人 严重违法
                }else if(beans.get(position).getCode().equals(Constants.EyeCheck_BZXR_TYPE)
                        ||beans.get(position).getCode().equals(Constants.EyeCheck_GBJG_TYPE)
                        ||beans.get(position).getCode().equals(Constants.EyeCheck_GPFH_TYPE)
                        ||beans.get(position).getCode().equals(Constants.EyeCheck_GBBD_TYPE)
                        ||beans.get(position).getCode().equals(Constants.EyeCheck_SXR_TYPE)
                        ||beans.get(position).getCode().equals(Constants.EyeCheck_YZWF_TYPE)){
                    context.startActivity(new Intent().setClass(context, BzxrDetailActivity.class)
                            .putExtra("title",beans.get(position).getName())
                            .putExtra("type",beans.get(position).getCode())
                            .putExtra("proId",((ZhoubianActivity)context).getMySelectCompany().getProId())
                            .putExtra("cmpanyType",((ZhoubianActivity)context).getMySelectCompany().getType())
                            .putExtra("companyId",((ZhoubianActivity)context).getMySelectCompany().getId()));
                // 股票行情
                }else if(beans.get(position).getCode().equals(Constants.EyeCheck_GPHQ_TYPE)){
                    context.startActivity(new Intent().setClass(context, GphqDetailActivity.class)
                            .putExtra("title",beans.get(position).getName())
                            .putExtra("type",beans.get(position).getCode())
                            .putExtra("proId",((ZhoubianActivity)context).getMySelectCompany().getProId())
                            .putExtra("cmpanyType",((ZhoubianActivity)context).getMySelectCompany().getType())
                            .putExtra("companyId",((ZhoubianActivity)context).getMySelectCompany().getId()));
                    // 股权出质
                }
//                else if(beans.get(position).getCode().equals(Constants.EyeCheck_GQCZ_TYPE)){
//                    context.startActivity(new Intent().setClass(context, GqczDetailActivity.class)
//                            .putExtra("title",beans.get(position).getName())
//                            .putExtra("type",beans.get(position).getCode())
//                            .putExtra("proId",((ZhoubianActivity)context).getMySelectCompany().getProId())
//                            .putExtra("cmpanyType",((ZhoubianActivity)context).getMySelectCompany().getType())
//                            .putExtra("companyId",((ZhoubianActivity)context).getMySelectCompany().getId()));
//                }
                else{
                    ToastUtils.showToast(context,"暂无数据");
                }

            }
        });
    }

    @Override
    public int getItemCount() {
        return beans == null ? 0 : beans.size();
    }

    class ItemHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tab_item_img)
        ImageView tab_item_img;
        @BindView(R.id.tab_item_num_tv)
        TextView tab_item_num_tv;
        @BindView(R.id.tab_item_textview)
        TextView tab_item_textview;
        @BindView(R.id.ll_item)
        LinearLayout ll_item;

        public ItemHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}